﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;


namespace WpfApp_91.acceso
{
    public static class operaciones
    {
       //  <summary>
       //ejecuta instruciones SELECT 
       //</summary>
       //<param name="sql"></param>
       //<returns></returns>

        public static DataTable Mostrar(string sql)
        {
            try
            {
                OleDbDataAdapter da = new OleDbDataAdapter(sql, conexion.OpenConexion());
                DataTable dt = new DataTable();
                int n = da.Fill(dt);
                conexion.CLoseConexion();
                return dt;
            }
            catch (Exception)
            {
                return null;
            }
        }
      
       //<summary>
       //Ejecuta instruccines  insert, delete y update
       //</summary>
       //<param name="sql"></param>
       //<returns></returns>
      public static bool Operacion_general(string sql) {
          try
          {
              OleDbCommand cmd = new OleDbCommand(sql, acceso.conexion.OpenConexion());
              
              int n = cmd.ExecuteNonQuery();          

              conexion.CLoseConexion();
              return n > 0;

          }
          catch (Exception)
          {

              return false;
          }
      }
      public static DataTable CargarDataGrid(string sql)
      {
          try
          {
              OleDbDataAdapter da = new OleDbDataAdapter(sql, acceso.conexion.OpenConexion());
              DataTable dt = new DataTable();
              int n = da.Fill(dt);
              conexion.CLoseConexion();
              return dt;
          }
          catch (Exception)
          {
              return null;
          }
      
      }
      public static DataTable Login(string sql)
      {
          try
          {
              OleDbDataAdapter da = new OleDbDataAdapter(sql, acceso.conexion.OpenConexion());
              DataTable dt = new DataTable();
              int n = da.Fill(dt);
              conexion.CLoseConexion();
              return dt;
          }
          catch (Exception)
          {
              return null;
          }
      }
   }    
  }
    
